package com.xukai.springboot.service.statistics;

import com.xukai.springboot.datalayer.statis.ChartSettingMapper;
import com.xukai.springboot.datalayer.sys.ChartTypeMapper;
import com.xukai.springboot.entity.statistics.t_statis_chart_setting;
import com.xukai.springboot.entity.sys.t_sys_chart_type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 图表设置服务
 */
@Service
public class ChartSettingService {

    @Autowired
    ChartSettingMapper chartSettingMapper;

    @Autowired
    ChartTypeMapper chartTypeMapper;


    /**
     * 获取图表设置列表
     */
    public List<t_statis_chart_setting> GetChartSettingList(int chartType, String chartName, int start, int pageSize, int state) {
        return chartSettingMapper.GetChartSettingList(chartType, chartName, start, pageSize, state);
    }

    /**
     * 新建图表设置信息
     */
    public t_statis_chart_setting AddChartSetting(t_statis_chart_setting data) {
        data.setCreateTime(new Date());
        chartSettingMapper.AddChartSetting(data);
        return data;
    }

    /**
     * 获取图表设置数据
     */
    public t_statis_chart_setting GetChartSettingDetail(int id) {
        return chartSettingMapper.GetChartSettingDetail(id);
    }

    /**
     * 修改图表基本信息
     */
    public void UpdateChartSetting(t_statis_chart_setting data) {
        chartSettingMapper.UpdateChartSetting(data);
    }

    /**
     * 修改图表json设置
     */
    public void UpdateChartSettingJsonData(t_statis_chart_setting data) {
        chartSettingMapper.UpdateChartSettingJsonData(data.getId(), data.getData(), data.getState());
    }

    /**
     * 删除图表设置
     */
    public void DelChartSetting(int id) {
        chartSettingMapper.DelChartSetting(id);
    }

    /**
     * 获取图表类型列表
     *
     * @return
     */
    public List<t_sys_chart_type> GetChartTypeList() {
        return chartTypeMapper.GetChartTypeList();
    }

    /**
     * 获取图表默认配置
     */
    public String GetChartDefaultOption(int id) {
        return chartTypeMapper.GetDefaultOption(id);
    }

    /**
     * 获取图表设置总数
     *
     * @param chartType
     * @param chartName
     * @return
     */
    public int GetDataCount(int chartType, String chartName, int state) {
        return chartSettingMapper.GetChartSettingCount(chartType, chartName, state);
    }

}
